package pers.zc.activiti.aop;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @description aop测试类
 * @Author Lin FuYuan
 * @date 2020/1/9
 */
@Aspect
@Component
public class AopTestAspect {
//    //定义变量
//    private String after;
//    private String before;
//    private String throwStr;


    @Pointcut("execution(* pers.zc.activiti.aop.MuBiaoClass.test(..))")
    public void pointCut(){

    }
    @Before(value="pointCut()")
    public void before(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        String  before = "before :    "+JSON.toJSONString(args[0]);
        System.out.println(before);
    }

    @AfterReturning(value="pointCut()",returning = "returnValue")
    public void saveSysLog(JoinPoint joinPoint,Object returnValue) {
        String after = "after :    "+JSON.toJSONString(returnValue);
        System.out.println(after);
//        next();
    }

    @AfterThrowing(value="pointCut()",throwing = "e")
    public void throwing(JoinPoint joinPoint,Exception e){
        String throwStr = e.getMessage();
        System.out.println(throwStr);
//        next();
    }

    public void next(){
        System.out.println();
        System.out.println("↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
//        System.out.println("→"+before);
//        System.out.println("→"+after);
//        System.out.println("→"+throwStr);
        System.out.println("↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑");
        System.out.println();
    }
}
